<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加店员信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="padding: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input username" lay-verify="required" name="username" placeholder="请输入用户名">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input newsName"  name="password" lay-verify="required" placeholder="请输入密码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input"  name="name" lay-verify="required" placeholder="请输入姓名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input"  name="phone" lay-verify="required" placeholder="请输入手机号码">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择角色</label>
        <div class="layui-input-block"  >
            <select name="roleId" lay-verify="required" id="roleId">
                <option value="">--请选择角色--</option>
            </select>
        </div>
    </div>

    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">选择门店</label>-->
        <!--<div class="layui-input-block"  >-->
            <!--<select name="merchantId" lay-verify="required" id="merchantId">-->
                <!--<option value="">&#45;&#45;请选择门店&#45;&#45;</option>-->
            <!--</select>-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addClerks">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script type="text/javascript">


    layui.config({
        base : "js/"
    }).use(['form','layer','jquery','layedit','laydate'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            laypage = layui.laypage,
            layedit = layui.layedit,
            laydate = layui.laydate,
            $ = layui.jquery;


        $.ajax({
            type : "GET",
            url: '/merchants/merchants.json',
            dataType:'json',
            async:false,
            success: function(data){
                var list=data.data;
                var html='';
                for(var i=0;i<list.length;i++){
                    html += "<option value='"+list[i].id+"'>"+list[i].name+"</option>"
                }
                $("#merchantId").append(html);
                form.render();
            }
        });

        $.ajax({
            type : "GET",
            url: '/roles/roles.json',
            dataType:'json',
            async:false,
            success: function(data){
                var list=data.data;
                var html='';
                for(var i=0;i<list.length;i++){
                    html += "<option value='"+list[i].id+"'>"+list[i].roledesc+"</option>"
                }
                $("#roleId").append(html);
                form.render();
            }
        });
        //创建一个编辑器
        form.on("submit(addClerks)",function(data){
            var datas=data.field;

            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.ajax({
                type: "POST",
                url:"/clerks/add",
                data:JSON.stringify(datas),// 序列化表单值
                contentType:"application/json",
                success: function(res) {
                    if(res.code==2000){
                        top.layer.close(index);
                        top.layer.msg("添加成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    }else{
                        top.layer.msg(res.msg);
                    }

                } ,

                error: function(res) {
                    alert("请求错误");
                }
            });
            return false;
        })

    })
</script>
</body>
</html>